<include file='Public/header'/> 
   <style> 
        .vc-cells .vc-img-cell .cell-text{ margin-left: 0px;}
        .vc-cells .vc-img-cell .cell-time.actime{text-align: left;margin-top:5px;margin-bottom:5px;}
        .vc-cells .vc-img-cell .cell-subtitle{white-space:unset;}
        .vc-cells .vc-img-cell .cell-text{width:100%!important;}
        .cell-rig{float: right;}
        .weui-flex__item{color: #333;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;font-size: 14px;line-height: 25px;}
        .vc-img-cell:nth-child(2n){background:#f5f5f5;}
    </style>
</head>
<body> 
    
    <include file='Public/navigationer'/> 

    <div class="weui-loadmore">
        <i class="weui-loading"></i>
        <span class="weui-loadmore__tips">加载中</span>
    </div>
    <div class="articles-wrapper" style='padding-bottom: 70px;'> 
        <div class="vc-cells"></div>
    </div> 
    <p class="no-more">暂无更多数据</p>
    
    <include file='Public/comjs'/> 
    <!-- private -->
    <script src="__PUBLIC__/Wap/js/vc-utils.js"></script>
    <script>
        
        $(document).ready(function () {

            var currentPage = 1; /*当前页码*/
            var loadEnd = false; /*请求结束标记*/
            var pageSize = 20; /*size*/
            var loadFlag = 0; //请求更多的标记
            var data_model = {id:"", img_url:"", title: "", sub_title: "", create_time: "" } //cell数据模型
            
            /**
             * 首次进入请求
             * @return {[void]}
             */
            requestArticles("fresh");
            function requestArticles(request_type) {
                if (request_type == "fresh") {
                    $(".weui-loadmore").css("display","block");
                }
                $.post(base_url + "Home/index/baobeilists",{page: currentPage},function (response) {
                    console.log(response)
                    loadFlag = 0; //请求结束后标记重置，防止多次请求
                    var result_data = response.data;
                    console.log(currentPage);
                    $(".weui-loadmore").css("display","none");
                    if (response.status == "1" &&　result_data != null) {
                        currentPage ++;
                        if (result_data.length < page_size) {
                            $(".no-more").css("display","block");
                        }else {
                            $(".no-more").css("display","none");
                        }
                        for (var i = 0; i < result_data.length; i++) {

                            var i_data = result_data[i];
                            data_model.id = i_data["id"];
                            data_model.projectTitle = i_data["project_title"]; 
                            data_model.name = i_data["name"];
                            data_model.tel = i_data["tel"];
                            data_model.create_time = temp2time(i_data["create_time"]).format("yyyy-MM-dd hh:mm");
                            if(i_data["status"]==1){
                                data_model.status_text = '已通过' ;
                            }else if(i_data["status"]==0){
                                data_model.status_text = '待审核' ;
                            }else if(i_data["status"]==-1){
                                data_model.status_text = '已拒绝' ;
                            }else if(i_data["status"]==2){
                                data_model.status_text = '已到访' ;
                            }else if(i_data["status"]==3){
                                data_model.status_text = '已失效' ;
                            }else if(i_data["status"]==4){
                                data_model.status_text = '已成交' ;
                            }
                            var cell_str = getCellStringWithModel(data_model);

                            $('.vc-cells').append(cell_str);
                        }
                        // 上拉加载结束
                        id_end = true;
                        $(".vc-img-cell").click(function () {
                            // console.log($(this).data("artid"))
                           
                        })
                    }else {
                        //处理请求失败
                    }
                    
                    
                })
            }
            $(document).on("click",".vc-img-cell", function () {
                return false ;
            })
            /**
             * create vc-cell with model
             * @param  {[Object]} model = {img_url:"", title: "", sub_title: ""}
             * @return {[String]}       [DOMElement String] 
             */
            function getCellStringWithModel(model) {
                var vc_cell = "<div class='vc-img-cell' data-artid='"+model.id+"'>"+ 
                    "<div class='cell-text'> <div class=\"weui-flex\">"+
                        "<div class=\"weui-flex__item\">项目："+model.projectTitle+"</div>"+
                        "<div class=\"weui-flex__item\">"+model.create_time+"</div>"+ 
                        "</div><div class=\"weui-flex\">"+"<div class=\"weui-flex__item\">"+model.name+"："+model.tel+"</div>"+
                        "<div class=\"weui-flex__item\">"+model.status_text+"</div>"+ 
                        "</div>"+ 
                    "</div></div>";
                return vc_cell;
            }
            loadmoreScroll(function () {
                requestArticles("more")     
            })
            
        })
    </script>
</body>
</html>